<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/dataTables.bootstrap.min.css">
<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
</head>
<body>
    <div>
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <div>
                <header style="height: 100%">
					 <div align="left">
                        <table style="width: 100%">
                            <tr>
                                <td>
									<form class="form-inline" onsubmit="return false">
										<div class="form-group">
											昵称：
											<input id="nickname" type="text" class="form-control" placeholder="昵称">
											时间：
											<input type="text" class="form-control" placeholder="开始时间" id="beginTime">
											<input type="text" class="form-control" placeholder="结束时间" id="endTime">
											状态：
											<select class="form-control input-sm" id="flag">
												<option value="">全部</option>
												<option value="1">成功</option>
												<option value="0">失败</option>
											</select>
											<button id="searchBt" class="layui-btn layui-btn-sm" permission="sys:log:query"><i class="layui-icon">&#xe615;</i>搜索</button>
										</div>
									</form>
								</td>
                            </tr> 
                        </table>
                    </div>
                </header>
                
                <div>
                    <div class="widget-body no-padding">
                        <table id="dt-table" class="table table-striped table-bordered table-hover" style="width:100%">
                            <thead>
                                <tr>
                                </tr>                       
                                <tr>
									<th width="5%">id</th>
									<th width="15%">昵称</th>
									<th width="20%">模块</th>
									<th width="5%">状态</th>
									<th>备注</th>
									<th width="15%">时间</th>
                                </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../js/my/permission.js"></script>
<script type="text/javascript">
var pers = checkPermission();
layui.use(['layer','laydate'], function(){
    var layer = layui.layer;
    var laydate = layui.laydate;
    laydate.render({
       elem: '#beginTime'
    });
    laydate.render({
       elem: '#endTime'
    });
});

var example;
function init(){
	example = 
    	$('#dt-table').DataTable({
        	"searching": false,
        	"processing": false,
        	"serverSide" : true,
        	"language": {
                "url": "/js/plugin/datatables/Chinese.lang"
            },
        	"ajax": {
        		"url" : "/logs",
        		"type":"get",
        		"data":function(d){
        			d.flag = $('#flag').val();
        			d.nickname = $('#nickname').val();
        			d.beginTime = $('#beginTime').val();
    				d.endTime = $('#endTime').val();
        		},
    			"error":function(xhr, textStatus, errorThrown){
    				var msg = xhr.responseText;
    				console.log(msg);
    				var response = JSON.parse(msg);
    				var code = response.code;
    				var message = response.message;
    				if (code == 400) {
    					layer.msg(message);
    				} else if (code == 401) {
    					localStorage.removeItem("token");
    					layer.msg("token过期，请先登录", {shift: -1, time: 1000}, function(){
    						location.href = '/login.html';
                        });
    				} else if (code == 403) {
    					console.log("未授权:" + message);
    					layer.msg('未授权');
    				} else if (code == 500) {
    					layer.msg('系统错误：' + message);
    				}
    			}
        	},
        	"dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'col-sm-10 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-10' p v>>",	
            "columns": [
				{"data" : "id", "defaultContent" : ""},
				{
					"data" : "user", 
					"defaultContent" : "",
					"orderable":false,
					"render": function (data, type, row) {
                		var user = row['user'];
                        return user['nickname'];
                  	}
				},
				{"data" : "module", "defaultContent" : ""},
				{
					"data" : "flag", 
					"defaultContent" : "",
					"render": function (data, type, row) {
                		var flag = row['flag'];
                        return flag ? "成功":"失败";
                  	}
				},
				{"data" : "remark", "defaultContent" : ""},
				{"data" : "createTime", "defaultContent" : ""},

                
            ],
           "order": [[ 5, "desc" ]]
        } );
}

$("#searchBt").click(function(){
	example.ajax.reload();
});

init();
</script>
